﻿using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace SpecDemo
{
    [Activity(Label = "SpecDemo", MainLauncher = false, Icon = "@drawable/icon")]
    public class TouchActivity : Activity
    {
        int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.DragBtn);

            var btn = FindViewById<Button>(Resource.Id.btn);

            btn.Touch += new EventHandler<View.TouchEventArgs>(btn_Touch);
        }
        int[] temp = new int[] { 0, 0 };  
        void btn_Touch(object sender, View.TouchEventArgs e)
        {
            View v = (View) sender;
                var action = e.Event.Action;  
  
                int x = (int) e.Event.RawX;  
                int y = (int) e.Event.RawY;  
  
                switch (action) {  
  
                case MotionEventActions.Down: // touch down so check if the  
                    temp[0] = (int) e.Event.GetX();  
                    temp[1] = y - v.Top;  
                    break;  
  
                case MotionEventActions.Move: // touch drag with the ball  
                    v.Layout(x - temp[0], y - temp[1], x + v.Width  
                            - temp[0], y - temp[1] + v.Height);  
                    break;  
  
                case MotionEventActions.Up:  
                    break;  
                }  
        }
    }
}

